package com.example.webapp.service.impl;

import com.example.webapp.bean.Exam;
import com.example.webapp.bean.StudentExam;
import com.example.webapp.bean.User;
import com.example.webapp.dao.StudentExamDao;
import com.example.webapp.service.StudentExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentExamServiceImpl implements StudentExamService {

    @Autowired
    private final StudentExamDao studentExamDao;

    public StudentExamServiceImpl(StudentExamDao studentExam) {
        studentExamDao = studentExam;
    }

    @Override
    public void createStudentExam(StudentExam registration) {
        studentExamDao.save(registration);
    }

    @Override
    public void updateStudentExam(StudentExam registration) {
        studentExamDao.save(registration);
    }

    @Override
    public void deleteStudentExam(Integer id) {
        studentExamDao.deleteById(id);
    }

    @Override
    public StudentExam getStudentExamById(Integer id) {
        return studentExamDao.findById(id).orElse(null);
    }

    @Override
    public List<StudentExam> findStudentExamsByStudentAndExam(User user, Exam exam) {
        return studentExamDao.findStudentExamsByStudentAndExam(user,exam);
    }
}